package com.axjy.controller;

import com.axjy.pojo.Permission;
import com.axjy.service.PermissionService;
import com.axjy.util.Log;
import com.axjy.vo.NodeVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sys/permission")
public class PermissionController {

    @Resource
    private PermissionService permissionService;

    private String msg;

    @GetMapping("/search4Tree/{roleId}")
    public List<NodeVo> search4Tree(@PathVariable("roleId") Integer roleId){
        return permissionService.search4Tree(roleId);
    }

    @PostMapping("/grant")
    public String grant(Integer roleId,Integer[] menuIds){
        try{
            permissionService.grant(roleId,menuIds);
            msg="角色授权成功！";
        }catch (Exception ex){
            msg="角色授权失败！";
            Log.logger.error(msg,ex);
        }
        return msg;
    }


}
